<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>裂变营销</title>
</head>
<style>
    .form-horizontal .form-group.wu-margin {
        margin-left: 0;
        margin-right: 0;
    }

    .wu-pos-b {
        box-sizing: border-box;
        width: 365px;
        left: auto;
        right: 0;
        top: 167px;
    }

    .calcH59 {
        /*定位距离*/
        padding-top: 39px;
        /*Standard */
        height: calc(100% - 59px);
        /*Firefox*/
        height: -moz-calc(100% - 59px);
        /*chrome safari*/
        height: -webkit-calc(100% - 59px);

    }

    .calcH32 {
        /*定位距离*/
        padding-top: 43px;
        /*Standard */
        height: calc(100% - 32px);
        /*Firefox*/
        height: -moz-calc(100% - 32px);
        /*chrome safari*/
        height: -webkit-calc(100% - 32px);

    }
    .wu-cash{
        height: 110px;
        margin: 10px;
        background: #f97c33;
        /* border: 1px solid #969594; */
        border-radius: 5px;
        box-shadow: 1px 1px 5px #999;
        -webkit-box-shadow: 1px 1px 5px #999;
        -moz-box-shadow: 1px 1px 5px #999;
    }
    .wu-cash>div{
        float: left;
        height: 100%;
        width: 35%;
        position: relative;
    }
    .wu-cash>div.cashDetail{
        width: 60%;
        margin-left: 3%;
    }
    .wu-cash p{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translateX(-50%) translateY(-50%);
    }
    .wu-size{
        font-size: 4rem;
    }
    .cashUl{
        padding-top: 10px;
    }
    .cashUl>li{
        margin-bottom: 3px;
    }
    .cashUl>li.cashTitle{
        font-size: 1.8rem;
        font-weight: 600;
        font-weight: bold;
    }
    .calcH32 .row{
        margin-right: 0;
        margin-left: 0;
    }
    .wu-fixed{
        background:#fff;
        padding-top: 11px;
        position: fixed;
        width: 100%;
        overflow: hidden;
        z-index: 999;
    }
</style>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>
    裂变营销
    <span class="c-gray en">&gt;</span>
    营销配置
</nav>
<div class="page-container calcH59">
    <div id="tab_marketing" class="HuiTab" style="height: 100%;">
        <div class="tabBar clearfix wu-fixed">
            <span>礼包配置</span>
        </div>
<!--****************注册有礼基本配置***************-->
        <div class="tabCon pos-r calcH32">
            <div style="margin-right: 365px;height: 100%;">
                <div class="pt-20" style="height: 100%;">
                    <!--************礼包信息************-->
                    <div class="form-unit">礼包信息</div>
                    <div class="row">
                        <div class="col-xs-12">
                            <table id="RegisterPackage" class="table table-bordered table-striped text-center"></table>
                        </div>
                    </div>

                    <!--************优惠劵信息************-->
                    <div class="form-unit pt-25">优惠劵信息</div>
                    <div class="row">
                        <div id="RegisterTableToolbar">
                            <button class="btn btn-primary radius"
                                    data-toggle="modal"
                                    data-target=".marketing-modal"
                                    onclick="platformMarketingMarketingFun.registerRule_click()">
                                增加优惠劵
                            </button>
                            <button id="RegisterAddBtn" class="btn btn-warning radius"
                                    onclick="platformMarketingMarketingFun.registerPackageList_click()">
                                <i class="Hui-iconfont">&#xe600;</i>
                                添加至优惠劵列表
                            </button>
                        </div>
                        <div class="col-xs-12">
                            <table id="RegisterTable" class="table table-bordered table-striped text-center">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="pos-a wu-pos-b">
                <div class="wu-tree">优惠劵展示</div>
                <div>
                    <ul id="cashListShow"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<!--******************编辑礼包模态框****************-->
<div class="modal fade " tabindex="-1" role="dialog" id="registerPackageupdate-modal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑礼包</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" id="registerPackageupdate-form">
                    <div class="box-body">
                        <div class="row">
                            <div class="form-group " style="display: none;">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>packageId：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" value="" id="registerPackageupdate-packageId" name="packageId">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>礼包名称：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" value="" id="registerPackageupdate-ruleName" name="ruleName">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>开始时间：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control input-text Wdate" value=""
                                           onfocus="WdatePicker({readOnly:true, dateFmt: 'yyyy-MM-dd HH:mm:ss'})" id="registerPackageupdate-startTime" name="startTimes">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>结束时间：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control input-text Wdate" value=""
                                           onfocus="WdatePicker({readOnly:true, dateFmt: 'yyyy-MM-dd HH:mm:ss'})" id="registerPackageupdate-endTime" name="endTimes">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button onclick="platformMarketingMarketingFun.registerPackageEdit()" type="button" class="btn btn-primary">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>

        </div>
    </div>
</div>
<!--******************添加优惠券模态框****************-->
<div class="modal fade marketing-modal" tabindex="-1" role="dialog" id="registerRule-modal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">添加优惠劵</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" id="registerRule-form">
                    <div class="box-body">
                        <div class="row">
                            <input value="1" style="display: none;"/>
                            <div class="form-group">
                                <div class="  col-sm-7">
                                    <input type="text" class="form-control" style="display: none;" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>券的类型：</label>
                                <div class="  col-sm-7">
                                    <select class="form-control" id="registerRule-ruleType" name="ruleType">
                                        <option value ="1">满减券</option>
                                        <option value ="2">折扣券</option>
                                        <option value="4">美容抵用券</option>
                                        <option value="5">光速洗车抵用券</option>
                                        <option value="6">内饰清洗抵用券</option>
                                        <option value="8">建行龙卡抵用券</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>规则名称：</label>
                                <div class="  col-sm-7">
                                    <input type="text" class="form-control" id="registerRule-ruleName" name="ruleName">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>规则标题：</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" id="registerRule-ruleTitle" name="ruleTitle">
                                </div>
                            </div>
                            <div class="form-group" id="registerRule-man">
                                <label class="control-label col-sm-3">满：</label>
                                <div class="formControls  col-sm-7">
                                    <input type="text" id="registerRule-minPayAmount" name="minPayAmount"  class="form-control">
                                </div>
                            </div>
                            <div class="form-group" id="registerRule-jian">
                                <label class="control-label col-sm-3" id="tempJian">减：</label>
                                <div class="formControls  col-sm-7">
                                    <input type="text" id="registerRule-deductAmount" name="deductAmount"  class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-3">规则内容：</label>
                                <div class="formControls  col-sm-7">
                                    <textarea id="registerRule-ruleContent" name="ruleContent" cols="80" rows="3" class="form-control" placeholder="请输入使用规则..."></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label  col-sm-3"><span class="c-red"></span>使用期限：</label>
                                <div class="form-inline text-left">
                                    <div class="form-group wu-margin">
                                        &nbsp;&nbsp;&nbsp;&nbsp;<input class="form-control" id="registerRule-validDays" name="validDays" style="width: 220px">&nbsp;&nbsp;天
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" onClick="platformMarketingMarketingFun.registerRuleAdd()" class="btn btn-primary">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>

        </div>
    </div>
</div>
<script type="text/template" id="cashTemplate">
    {{each modelList}}
    <li>
        <div class="wu-cash">
            <div>
                <p class="text-center">
                    <span class="wu-size">{{$value.deductAmount/100}}</span>元
                </p>
            </div>
            <div class="cashDetail">
                <ul class="cashUl">
                    <li class="cashTitle">专享洗车优惠劵</li>
                    <li>{{$value.ruleName}}</li>
                    <li>有效期至{{$value.endTime}}</li>
                    <li>满{{$value.minPayAmount/100}}元使用</li>
                </ul>
            </div>
        </div>
    </li>
    {{/each}}
</script>
<script>
    /*裂变营销配置 platformMarketingMarketingFun*/
    var platformMarketingMarketingFun;

    platformMarketingMarketingFun = {
        wuSelect: null,
        wuRow : null,
        voucherSelect:null,
        voucherRow:null,

        init: function () {
            let self = this;
            self.bootstrapvalidatorForm();

            //券的类型选项，下拉框改变事件
            $("#registerRule-ruleType").change(function(){
                //触发的事件
                $("#registerRule-minPayAmount").val("");
                $("#registerRule-deductAmount").val("");

                switch($("#registerRule-ruleType option:selected").val().toString()) {
                    case "1":
                        $("#tempJian").text("减：");
                        $("#registerRule-man").show();
                        $("#registerRule-jian").show();
                        break;
                    case "2":
                        $("#tempJian").text("折扣：");
                        $("#registerRule-man").hide();
                        $("#registerRule-jian").show();
                        break;
                    default:
                        $("#registerRule-man").hide();
                        $("#registerRule-jian").hide();
                        break;
                }
            });

            $("#tab_marketing").Huitab({
                index: 0
            });
            //注册有礼table
            $('#RegisterTable').bootstrapTable({
                url: 'mkt/showAllMktRule',         //请求后台的URL（*）
                method: 'get',
                toolbar: '#RegisterTableToolbar',                //工具按钮用哪个容器
                toolbarAlign : "right",
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 20,                       //每页的记录行数（*）
                pageList: [20, 50, 70, 100],        //可供选择的每页的行数（*）
                //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                //minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                detailView: true, //是否显示父子表
                detailFormatter : function (index, row) {
                    let html = `
                     <form class="form-horizontal" method="post" id="marketingRule${row.ruleId}">
                <div class="box-body">
                    <div class="row">
                        <input value="1" style="display: none;"/>
                        <div class="form-group">
                            <div class="  col-sm-7">
                                <input type="text" class="form-control" value="${row.ruleId}" style="display: none;" name="ruleId">
                                <input type="text" class="form-control" value="${row.ruleType}" style="display: none;" name="ruleType">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label  col-sm-3"><span class="c-red"></span>规则名称：</label>
                            <div class="  col-sm-7">
                                <input type="text" class="form-control" value="${row.ruleName}" placeholder=""  name="ruleName">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label  col-sm-3"><span class="c-red"></span>规则标题：</label>
                            <div class="col-sm-7">
                                <input type="text" class="form-control" value="${row.ruleTitle}" placeholder="" name="ruleTitle">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-sm-3">规则内容：</label>
                            <div class="formControls  col-sm-7">
                                <textarea cols="80" rows="3" class="form-control" placeholder="请输入使用规则..." name="ruleContent">${row.ruleContent}</textarea>
                            </div>
                        </div>

                        <div class="form-group" style="display: ${row.deductAmount == null?'none':'block'};">
                            <label class="control-label  col-sm-3"><span class="c-red"></span>红包面额：</label>
                            <div class="col-sm-7">
                                <div class="row">
                                    <div class="form-inline text-left" style="padding-left: 15px;">
                                        <div class="form-group wu-margin" style="display: ${row.minPayAmount == null?'none':'inline-block'};">
                                            <label>满</label>
                                            <input class="form-control" placeholder="元"  style="width: 80px" value="${row.minPayAmount/100}" name="minPayAmount">
                                        </div>
                                        <div class="form-group wu-margin">
                                            <label style="display: ${row.minPayAmount == null?'none':'inline-block'};">减</label>
                                            <input class="form-control" placeholder="元" style="width: 80px"
                                                   value="${row.minPayAmount == null?row.deductAmount/10:row.deductAmount/100}" name="deductAmount">
                                            <label style="display: ${row.minPayAmount == null?'inline-block':'none'};">折</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label  col-sm-3"><span class="c-red"></span>使用期限：</label>
                            <div class="col-sm-7 form-inline text-left" style="padding-left: 15px;">
                                <input type="text" class="form-control" placeholder="" value="${row.validDays}" name="validDays">&nbsp;&nbsp;天
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                                <input onclick="platformMarketingMarketingFun.submitAction(${row.ruleId});return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                            </div>
                        </div>

                    </div>
                </div>
            </form>
                    `
                    return html;
                },
                columns: [
                    {
                        field: 'state',
                        checkbox: true
                    },
                    {
                        field: 'ruleId',
                        title: 'ID',
                        visible: false
                    }, {
                        field: 'ruleName',
                        title: '规则名称'
                    }, {
                        field: 'ruleTitle',
                        title: '规则标题'
                    }, {
                        field: 'ruleContent',
                        title: '规则内容'
                    }, {
                        field: 'minPayAmount',
                        title: '最低消费额',
                        formatter:function(value,row,index){
                            if(value != null){
                                return value/100;
                            }
                        }
                    }, {
                        field: 'deductAmount',
                        title: '抵扣金额',
                        formatter:function(value,row,index){
                            if(value != null){
                                if(row.minPayAmount == null){
                                    return value/10 + "折";
                                }
                                return value/100;
                            }
                        }
                    }, {
                        field: 'validDays',
                        title: '有效天数'
                    }
                ],
                onCheck : function (rows) {
                    //alert('选了：' + JSON.stringify(rows))
                    //$('#testDiv').html(self.renderTemp('testTemp',[rows]));
                }
            });

            self.bindEvent();
            self.loadRegisterPackage();
        },
        bindEvent : function () {
            let self = this;
           $("#RegisterAddBtn").on("click",function () {
               let cashList = $("#RegisterTable").bootstrapTable('getAllSelections');
               $('#cashListShow').html(self.renderTemp('cashTemplate',cashList));
           })
        },
        renderTemp:function (tempId,data) {
            /*data为数组格式*/
            let dataObj = {modelList : data};
            return template(tempId,dataObj)
        },
        //增加优惠券
        registerRuleAdd:function () {
            var temp = $("#registerRule-form").serializeArray();
            var ruleTypeTemp;
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'ruleType'){
                    ruleTypeTemp = temp[i].value;
                }
            }
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'minPayAmount'){
                    temp[i].value = temp[i].value*100;
                }
                if(temp[i].name == 'deductAmount'){
                    if(ruleTypeTemp == 2){
                        temp[i].value = temp[i].value*10;
                    }else {
                        temp[i].value = temp[i].value*100;
                    }
                }
            }

            //提交
            $.ajax({
                type: "post",
                url: "mkt/insertMktRule",
                data: temp,
                dataType: "json",
                success: function(data){
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //重新查询一次表格数据
                        $.ajax({
                            type: "get",
                            url: "mkt/showAllMktRule",
                            dataType:"json",
                            success : function(json) {
                                $("#RegisterTable").bootstrapTable('load', json);

                                $("#registerRule-modal").modal("hide");
                            }
                        })
                        return true;
                    }else {
                        layer.msg("修改失败！", {icon: 2});
                        return false;
                    }
                },
                error:function () {
                    alert("error");
                }
            });
        },
        submitAction: function (id) {
            id = "marketingRule"+id;

            //将元转为分
            var temp = $("#"+id).serializeArray();
            var ruleTypeTemp;
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'ruleType'){
                    ruleTypeTemp = temp[i].value;
                }
            }
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'minPayAmount'){
                    temp[i].value = temp[i].value*100;
                }
                if(temp[i].name == 'deductAmount'){
                    if(ruleTypeTemp == 2){
                        temp[i].value = temp[i].value*10;
                    }else {
                        temp[i].value = temp[i].value*100;
                    }
                }
            }
            //提交
            $.ajax({
                type: "post",
                    url: "mkt/modifyMktRule",
                data: temp,
                dataType: "json",
                success: function(data){
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //重新查询一次表格数据
                        $.ajax({
                            type: "get",
                            url: "mkt/showAllMktRule",
                            dataType:"json",
                            success : function(json) {
                                $("#RegisterTable").bootstrapTable('load', json);
                            }
                        })
                        return true;
                    }else {
                        layer.msg("修改失败！", {icon: 2});
                        return false;
                    }
                },
                error:function () {
                    alert("error");
                }
            });
        },
        //加载注册礼包信息
        loadRegisterPackage : function () {
            let self = this;
            /*********注册礼包信息***************/
            $('#RegisterPackage').bootstrapTable({
                url: 'mkt/showAllRegisterPackages',         //请求后台的URL（*）
                method: 'get',
                toolbar: '#RegisterTableToolbar2',                //工具按钮用哪个容器
                toolbarAlign : "left",
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                //minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                singleSelect : true,
                columns: [
                    {
                        field: 'packageId',
                        title: 'ID',
                        visible: false
                    }, {
                        field: 'ruleName',
                        title: '礼包名称'
                    }, {
                        field: 'packageState',
                        title: '礼包状态',
                        formatter:function(value,row,index){
                            if(value == 1){
                                return '开启';
                            }else {
                                return '关闭';
                            }
                        }
                    }, {
                        field: 'startTime',
                        title: '开始时间'
                    }, {
                        field: 'endTime',
                        title: '结束时间'
                    }, {
                        field: 'address',
                        title: '操作',/******todo 修改删除的操作事件同‘商户中门店管理（store）的门店信息配置页面（manage.html）’*/
                        formatter : function (value, row,index) {
                            return `
                        <a class="btn btn-danger btn-sm" type="button"
                          onclick="platformMarketingMarketingFun.registerPackage_close('${row.packageId}','${row.packageState}')">禁用</a>
                        <a class="btn btn-success btn-sm" type="button"
                           onclick="platformMarketingMarketingFun.registerPackage_open('${row.packageId}','${row.packageState}')">启用</a>
                        <!--<a class="btn btn-default btn-sm" onclick="platformMarketingMarketingFun.del_registerPackage('${row.packageId}')">删除</a>-->
                        <a class="btn btn-info  btn-sm" type="button" onclick="platformMarketingMarketingFun.edit_registerPackage('${row.packageId}','${row.ruleName}','${row.startTime}','${row.endTime}')">编辑</a>

                    `;
                        }
                    }
                ],
                onClickRow : function (row, el) {
                    self.wuRow = row;
                    self.wuSelect = el;
                }
            });

            $('#RegisterPackage').on('click-row.bs.table', function (e, row, element) {
                    $('.success').removeClass('success');//去除之前选中的行的，选中样式
                    $(element).addClass('success');//添加当前选中的 success样式用于区别

                //如果重复点击同一个，取消所有选中的优惠券
                if(row.state){
                    var allTableData = $('#RegisterTable').bootstrapTable('getData');//获取表格的所有内容行
                    //取消所有选中
                    for( j=0;j<allTableData.length;j++) {
                        $('#RegisterTable').bootstrapTable('updateRow', {
                            index: j,
                            row: {
                                "state": false,  //不选中
                            }
                        });
                    }
                    //清空右侧出现的礼包列表
                    let cashList = "";
                    $('#cashListShow').html(self.renderTemp('cashTemplate',cashList));

                    return;
                }

                //获取该礼包中的优惠券集合
                $.ajax({
                    type: "get",
                    url: "mkt/getRulesByPackage?packageId="+row.packageId,
                    dataType: "json",
                    success: function(data){
                        var allTableData = $('#RegisterTable').bootstrapTable('getData');//获取表格的所有内容行
                        //取消所有选中
                        for(var j=0;j<allTableData.length;j++) {
                            $('#RegisterTable').bootstrapTable('updateRow', {
                                index: j,
                                row: {
                                    "state": false,  //不选中
                                }
                            });
                        }
                        //判断选中哪个优惠券
                        for(var j=0;j<allTableData.length;j++) {
                            for(var i=0;i<data.length;i++) {
                                if(allTableData[j].ruleId == data[i].ruleId){
                                    $('#RegisterTable').bootstrapTable('updateRow', {
                                        index: j,
                                        row: {
                                            "state": true,  //选中
                                        }
                                    });
                                }
                            }
                        }
                        //点击礼包行，右侧自动出现目前已经配置的礼包列表
                        let cashList = $("#RegisterTable").bootstrapTable('getAllSelections');
                        $('#cashListShow').html(self.renderTemp('cashTemplate',cashList));

                    },
                    error:function () {
                        alert("error");
                    }
                });

            });

        },
        //编辑注册礼包信息展示
        edit_registerPackage:function(packageId,ruleName,startTime,endTime){
            $('#registerPackageupdate-modal').modal("show");
            $('#registerPackageupdate-packageId').val(packageId);
            $('#registerPackageupdate-ruleName').val(ruleName);
            $('#registerPackageupdate-startTime').val(startTime);
            $('#registerPackageupdate-endTime').val(endTime);

        },
        //编辑注册礼包确认
        registerPackageEdit : function () {
            let _this = this;
            //bootstrap验证
            var bootstrapValidator = $("#registerPackageupdate-form").data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid())
                $("#registerPackageupdate-form").submit();
            else return;

            $.ajax({
                type: "get",
                url: "mkt/editPackageName",
                data:$("#registerPackageupdate-form").serialize(),
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //涮新table，关闭窗体
                        _this.reloadBootstrapTable("/mkt/showAllRegisterPackages","RegisterPackage");
                        $('#registerPackageupdate-modal').modal('hide')

                        return true;
                    }else {
                        layer.msg("修改失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert("error");
                }
            });
        },
        //重新加载bootstrapTable的公共方法
        reloadBootstrapTable : function (url,tableId) {
            $.ajax({
                type: "get",
                url: "/back"+url,
                dataType: "json",
                success: function (json) {
                    $("#"+tableId).bootstrapTable('load', json);
                }
            })
        },
        //点击增加优惠券，清空文本框
        registerRule_click : function () {
            /***********设置日期控件*********/
//            $("#registerRule-startTimes").on('focus',function () {
//                WdatePicker({
//                    el : this,
//                    readOnly:true,
//                    dateFmt: 'yyyy-MM-dd HH:mm:ss',
//                    startDate : '',
//                    isShowClear : false
//                })
//            });
            $("#registerRule-minPayAmount").val("");
            $("#registerRule-deductAmount").val("");
            $("#tempJian").text("减：");
            $("#registerRule-man").show();
            $("#registerRule-jian").show();

            $("#registerRule-ruleType").find("option").first().attr("selected",true);
            $("#registerRule-ruleName").val("");
            $("#registerRule-ruleTitle").val("");
            $("#registerRule-ruleContent").val("");
            $("#registerRule-validDays").val("");

            //重置validator
            $("#registerRule-form").data('bootstrapValidator').resetForm();
        },
        //禁用一个礼包
        registerPackage_close : function (index,state) {
            let _this = this;
            //判断该用户是否已经处于禁用
            if(state==0){
                layer.msg("该用户已经处于禁用状态！", {icon: 0});
                return;
            }

            $.ajax({
                type: "get",
                url: "mkt/openAndDisableRegisterPackages?packageState=0&packageId="+index,
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //涮新table
                        _this.reloadBootstrapTable("/mkt/showAllRegisterPackages","RegisterPackage");

                        return true;
                    }else {
                        layer.msg("禁用失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert("error");
                }
            });
        },
        //启用一个礼包
        registerPackage_open : function (index,state) {
            let _this = this;
            //判断该用户是否已经处于启用
            if(state==1){
                layer.msg("该用户已经处于启用状态！", {icon: 0});
                return;
            }

            $.ajax({
                type: "get",
                url: "mkt/openAndDisableRegisterPackages?packageState=1&packageId="+index,
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //涮新table
                        _this.reloadBootstrapTable("/mkt/showAllRegisterPackages","RegisterPackage");

                        return true;
                    }else {
                        layer.msg("启用失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert("error");
                }
            });
        },
        // 添加至优惠劵列表
        registerPackageList_click : function () {
            let self = this;
            var packageId = self.wuRow.packageId;//获得选中的行的id

            //判断，没有选中的check，返回提示
            if(packageId == undefined){
                layer.msg("请选择需要配置的礼包！", {icon: 0});
                return;
            }

            //获取选中的优惠券的行
            var getallRulesData = $('#RegisterTable').bootstrapTable('getData');//获取表格的所有内容行
            var arrRules = "";
            for(var j=0;j<getallRulesData.length;j++) {
                if(getallRulesData[j].state){
                    if(getallRulesData[j].ruleId){
                        if(arrRules != ""){
                            arrRules += ",";
                        }
                        arrRules += getallRulesData[j].ruleId;
                    }
                }
            }

            $.ajax({
                type: "get",
                url: "mkt/insertMktPackageRule",
                data:{packageId:packageId,arrRules:arrRules},
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //涮新table，关闭窗体
                        //_this.reloadBootstrapTable("/mkt/showAllMktRule","RegisterTable");
                        //$('#registerRule-modal').modal('hide')

                        return true;
                    }else {
                        layer.msg("新增失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert("error");
                }
            });

        },
        //bootstrap验证
        bootstrapvalidatorForm: function () {
            //编辑注册有礼礼包
            $('#registerPackageupdate-form').bootstrapValidator({
                message: 'This value is not valid',
                excluded : [':disabled'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    ruleName: {
                        validators: {
                            notEmpty: {
                                message: '礼包名称不能为空'
                            },
                            stringLength: {
                                min: 2,
                                max: 50,
                                message: '礼包名称长度必须在2到50位之间'
                            }
                        }
                    },
                    startTimes: {
                        validators: {
                            notEmpty: {
                                message: '开始时间不能为空'
                            }
                        }
                    },
                    endTimes: {
                        validators: {
                            notEmpty: {
                                message: '结束时间不能为空'
                            }
                        }
                    }
                }
            });
        }

    };
    platformMarketingMarketingFun.init();
</script>
</body>
</html>